import {storeBindingsBehavior} from 'mobx-miniprogram-bindings'
import {store} from "../store/store"

// custom-tab-bar/index.js
Component({
  // 挂在store
  behaviors:[storeBindingsBehavior],
  // 引入定义的 store 内容
  storeBindings:{
    // store 数据源
    store,
    fields:{
      msgNum: 'msgNum',
      active: 'activeTabBarIndex',
    },
    actions: {
      updataActive: 'updaActivetaTabBarIndex',
    }
  },
  // 数据监听 事件
  observers:{
    'msgNum': function(val) {
      this.setData({
        'list[1].info': val
      })
    }
  },

  options:{
    styleIsolation: 'shared',
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    // active: 0,
    list: [
      {
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "/icon/home.png",
        "selectedIconPath": "/icon/home-fill.png"
      },
      {
        "pagePath": "/pages/message/message",
        "text": "消息",
        "iconPath": "/icon/bell.png",
        "selectedIconPath": "/icon/bell-fill.png",
        info: 2
      },
      {
        "pagePath": "/pages/contact/contact",
        "text": "联系我们",
        "iconPath": "/icon/mail.png",
        "selectedIconPath": "/icon/mail-fill.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      // this.setData({ active: event.detail });
      this.updataActive(event.detail)
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})
